const { ipcRenderer } = require("electron");
const path = require('path')

document.getElementById("selectMusic").addEventListener("click", () => {
  // 通知主进程点击了选择音乐按钮
  ipcRenderer.send("open-music-file", "from add");
});

document.getElementById("add-Music").addEventListener("click", () => {
    // 通知主进程点击了导入音乐按钮
    ipcRenderer.send("add-tracks",musicFilesPath);
});

// 渲染dom的方法
const renderListHtml = (pathes) => {
    const musicList = document.getElementById('musicList')
    // console.log(pathes,'--------------------');
    let musicItemsHTML = ''
    pathes.forEach((item)=>{
        musicItemsHTML+=`<li class="list-group-item">${path.basename(item)}</li>`
    })
    musicList.innerHTML = `<ul class="list-group">${musicItemsHTML}</ul>`
}

let musicFilesPath = []
ipcRenderer.on('selected-file',(event,path)=>{
    // console.log(path);
    if(Array.isArray(path)){
        renderListHtml(path)
        musicFilesPath = path
    }
})
